﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDIOrganizer
{
    public static class RequestArrayExtensionMethods
    {
        public static bool DoesAnyCollideWith(this Request[] pRequests, Shift pShift, bool pCheckDateFrames)
        {
            var _query = pRequests.WhichCollideWith(new Shift[] { pShift }, pCheckDateFrames);
            if (_query == null || _query.Length == 0)
            {
                return false;
            }
            return true;
        }

        public static Request[] WhichCollideWith(this Request[] pRequests,
            Shift[] pShifts,
            bool pCheckDateFrames)
        {
            var _result = new List<Request>();
            foreach (var _request in pRequests)
            {
                foreach (var _shift in pShifts)
                {
                    if (_request.CollidesWith(_shift, pCheckDateFrames))
                    {
                        _result.Add(_request);
                    }
                }
            }
            return _result.Distinct().ToArray();
        }

        public static bool CollideWith(this Request[] pRequests, Shift[] pShifts, bool pCheckDateFrames)
        {
            foreach (var _shift in pShifts)
            {
                if(pRequests.DoesAnyCollideWith(_shift, pCheckDateFrames))
                    return true;
            }
            return false;
        }

        
    }
}
